package com.fxm.controller;

import com.fxm.client.AnswerClient;
import com.fxm.client.RuleClient;
import com.fxm.returns.RespEntity;
import com.fxm.returns.RespTable;
import com.fxm.vo.param.AnswerParam;
import com.fxm.vo.param.RuleParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 答题规则管理 前端控制器
 * </p>
 *
 * @author fxm
 * @since 2021-02-22
 */
@RestController
@RequestMapping("/rule")
@Slf4j
@Api(value = "答题规则管理", tags = "答题规则管理")
public class RuleController {

    @Autowired
    private RuleClient ruleClient;

    @GetMapping("/list")
    @ApiOperation(value = "答题规则列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "page", value = "当前页数", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "limit", value = "每页数量", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "questionTitle", value = "题目名称", required = false)
    })
    public RespTable ruleList(@RequestParam(value = "page", required = true) Integer page,
                                  @RequestParam(value = "limit", required = true) Integer limit) {
        RespTable respTable = ruleClient.ruleList(page, limit);
        return respTable;
    }

    @GetMapping("/search")
    @ApiOperation(value = "搜索用户")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "page", value = "当前页数", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "limit", value = "每页数量", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "username", value = "用户昵称", required = false)
    })
    public RespTable ruleSearch(@RequestParam(value = "page", required = true) Integer page,
                                    @RequestParam(value = "limit", required = true) Integer limit,
                                    @RequestParam(value = "username", required = false) String username) {
        RespTable respTable = ruleClient.searchRule(page, limit, username);
        return respTable;
    }

    @PutMapping("/update")
    @ApiOperation(value = "编辑答题规则")
    public RespEntity updateRule(RuleParam ruleParam) {
        RespEntity respEntity = ruleClient.updateRule(ruleParam);
        return respEntity;
    }

}
